package cn.chengpengper.seckill.activity.application.builder;


import cn.chengpengper.seckill.activity.application.command.SeckillActivityCommand;
import cn.chengpengper.seckill.activity.domain.model.entity.SeckillActivity;
import cn.chengpengper.seckill.common.builder.SeckillCommonBuilder;
import cn.chengpengper.seckill.common.code.HttpCode;
import cn.chengpengper.seckill.common.exception.SeckillException;
import cn.chengpengper.seckill.common.model.dto.SeckillActivityDTO;
import cn.chengpengper.seckill.common.utils.bean.BeanUtil;

import java.util.Objects;

/**
 * @author chengpeng.hu
 */
public class SeckillActivityBuilder extends SeckillCommonBuilder {

    public static SeckillActivity toSeckillActivity(SeckillActivityCommand seckillActivityCommand) {
        if (Objects.isNull(seckillActivityCommand)) {
            throw new SeckillException(HttpCode.PARAMS_INVALID);
        }
        SeckillActivity seckillActivity = new SeckillActivity();
        BeanUtil.copyProperties(seckillActivityCommand, seckillActivity);
        return seckillActivity;
    }

    public static SeckillActivityDTO toSeckillActivityDTO(SeckillActivity seckillActivity) {
        if (Objects.isNull(seckillActivity)) {
            throw new SeckillException(HttpCode.PARAMS_INVALID);
        }
        SeckillActivityDTO seckillActivityDTO = new SeckillActivityDTO();
        BeanUtil.copyProperties(seckillActivity, seckillActivityDTO);
        return seckillActivityDTO;
    }

}
